﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace myShop
{
    class LogFile
    {
        /*
         保存日志文件
         */

        public void doWriteLog(int iType, string sMsg)
        {
            string path = System.Environment.CurrentDirectory + "\\Log";
            if (!Directory.Exists(path))//判断是否存在
            {
                Directory.CreateDirectory(path);//创建新路径
            }

            string sDate = DateTime.Now.ToString("yyyyMMdd") + ".TXT";
            string sLogFile = path + "\\" + sDate;
            //Console.WriteLine("当前文件:" + sLogFile);

            if (File.Exists(sLogFile))
            {   //文件存在就追加
                StreamWriter sw = File.AppendText(sLogFile);
                sw.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + sMsg);
                sw.Flush();
                sw.Close();
            }
            else
            {
                //文件不存在就创建
                StreamWriter rw = File.CreateText(sLogFile);
                rw.WriteLine(DateTime.Now.ToLongTimeString().ToString() + ":" + sMsg);
                rw.Flush();
                rw.Close();
            }
        }
    }
}
